package com.example.first;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

public class ConfigActivity extends AppCompatActivity {
    private static final String TAG = "ConfigActivity";

    EditText dollarText;
    EditText euroText;
    EditText wonText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_config);
        Intent intent = getIntent();
        float dollar2 = intent.getFloatExtra("dollar_key",0.0f);
        float euro2 = intent.getFloatExtra("euro_key",0.0f);
        float won2 = intent.getFloatExtra("won_key",0.0f);

        Log.i(TAG,"onCreate:dollar2 =" + dollar2);
        Log.i(TAG,"onCreate:euro2 =" + euro2);
        Log.i(TAG,"onCreate:won2 =" + won2);

        dollarText = (EditText) findViewById(R.id.edit_dollar);
        euroText = (EditText) findViewById(R.id.edit_euro);
        wonText = (EditText) findViewById(R.id.edit_won);

        //显示数据到控件
        dollarText.setText(String.valueOf(dollar2));
        euroText.setText(String.valueOf(euro2));
        wonText.setText(String.valueOf(won2));
    }

        public void save(View btn){
            Log.i(TAG,"save:" );

            //获取新的值
            float newDollar = Float.parseFloat(dollarText.getText().toString());
            float newEuro = Float.parseFloat(euroText.getText().toString());
            float newWon = Float.parseFloat(wonText.getText().toString());

            Log.i(TAG,"save:获取到新的值");
            Log.i(TAG,"save:newDollar =" + newDollar);
            Log.i(TAG,"save:newEuro =" + newEuro);
            Log.i(TAG,"save:newWon =" + newWon);

            //保存到Bundle或放入到Extra
            Intent intent = getIntent();
            Bundle bdl = new Bundle();
            bdl.putFloat("new_dollar",newDollar);
            bdl.putFloat("new_euro",newEuro);
            bdl.putFloat("new_won",newWon);
            intent.putExtras(bdl);
            setResult(6,intent);

            //返回到调用界面
            finish();


        }




}